package testshijuan;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        /*(10分)4：确保输入一个大于0的整数，判断其是否是质数，质数的定义是只能被1和其本身整除的数。*/
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个大于0的整数：");
        int num4 = 0;
        while (true) {
            num4 = scan.nextInt();
            if (num4 > 0) {
                break;
            }
            System.out.println("输入有误，请重新输入！");
        }
        int i = 2;
        while (i * i < num4 && num4 % i != 0) {
            i++;
        }
        if (i * i > num4 && num4 != 1) {
            System.out.println(num4 + "是质数");
        } else {
            System.out.println(num4 + "不是质数");
        }
    }
}
